package com.cctc.mychat.server.handler;

import com.cctc.mychat.common.protocol.message.Message;
import com.cctc.mychat.common.session.SessionManager;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;

public class AuthHandler extends SimpleChannelInboundHandler<Message> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message message) throws Exception {
        if (!SessionManager.hasLogin(ctx.channel())) {
            System.err.println("[AuthHandler] 用户认证失败，关闭连接！！！");
            ctx.channel().close();
        } else {
            ctx.pipeline().remove(this);
            super.channelRead(ctx, message);
        }
    }
}
